package com.practice;

public class RunnableDemo implements Runnable{
    @Override
    public void run() {
        for (int i = 0; i <1001 ; i++) {
            System.out.println(Thread.currentThread().getName() + "运行了" + i + "次");
        }
    }

    public static void main(String[] args) {
        //得到线程的优先级
        //Thread.MAX_PRIORITY 最高优先级，值=10；
        //Thread.MIN_PRIORITY 最低优先级，值=1；
        //Thread.NORM_PRIORITY 默认优先级，值= 5；
        Thread.currentThread().setPriority(Thread.NORM_PRIORITY);
        System.out.println(Thread.currentThread().getPriority());

        Thread.currentThread().setName("主线程");
        //创建子线程对象
        Thread thread = new Thread(new RunnableDemo(),"子线程");
//        thread.setName("");
        Thread thread1 = new Thread(new Runnable() {
            @Override
            public void run() {
                for (int i = 0; i <100 ; i++) {
                    System.out.println(Thread.currentThread().getName());
                }
            }
        },"子线程2");

        //new Thread(() -> System.out.println(Thread.currentThread().getName()));

        thread1.start();
        for (int i = 0; i <1001 ; i++) {
            System.out.println(Thread.currentThread().getName() + "运行了" + i + "次");
        }
    }
}
